package view;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.io.FileFilter;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;

import model.Contact;
import controller.ModifyController;
import controller.ReturnController;
import controller.SaveController;
import controller.SaveModificationsController;

/**
 * This class displays the page that allows the user to makes modifications on a contacts
 * @author Marie Morin
 *
 */
public class ModifyWindow extends JPanel{
	
	private JLabel familyName = new JLabel("Family name :");
	private JTextField jtf_name = new JTextField();
	
	private JLabel firstName = new JLabel("First name :");
	private JTextField jtf_fname = new JTextField();
	
	private JLabel phone = new JLabel("Phone number :");
	private JTextField jtf_phone = new JTextField();
	
	private JLabel professionalPhone = new JLabel("Company phone number :");
	private JTextField jtf_professionalPhone = new JTextField();
	
	private JLabel homeAddress = new JLabel("Home address :");
	private JTextField jtf_homeAddress = new JTextField();
	
	private JLabel professionalAddress = new JLabel("Professional address :");
	private JTextField jtf_professionalAddress = new JTextField();
	
	private JLabel email = new JLabel("Email :");
	private JTextField jtf_email = new JTextField();	
	
	private JLabel website = new JLabel("Website :");
	private JTextField jtf_website = new JTextField();

	private JLabel group = new JLabel("Group :");
	private JTextField jtf_group = new JTextField();
	
	private JLabel l = new JLabel("Modify contact : ");
	
	private JButton b_picture = new JButton("Change picture");
	
	private JButton b_save = new JButton("Save");
	private JButton b_return = new JButton("Return");
	
	private SaveModificationsController s;
	
	private MainWindow w;
	private ReturnController r;
	private Contact c;

	public ModifyWindow(MainWindow w, Contact c) {
		
		
		this.w = w;
		this.c=c;
		this.Init();				
		
	}
	
	/**
	 * Initialize the parameters of the window
	 */
	public void  Init()
	{
		
		this.w.setLayoutNull();
		this.w.Init();
		
		l.setHorizontalAlignment(JLabel.CENTER);

		this.setLayout(new BorderLayout());
		
		JPanel p2 = new JPanel();
		
		jtf_fname.setText(c.getFname());
		jtf_name.setText(c.getName());
		jtf_phone.setText(c.getPhone());
		jtf_professionalPhone.setText(c.getProfessionalPhone());
		jtf_homeAddress.setText(c.getHomeAddress());
		jtf_professionalAddress.setText(c.getProfessionalAddress());
		jtf_email.setText(c.getEmail());
		jtf_website.setText(c.getWebsite());
		jtf_group.setText(c.getGroup());

		p2.add(familyName);
		p2.add(jtf_name);
		
		p2.add(firstName);
		p2.add(jtf_fname);

		p2.add(phone);
		p2.add(jtf_phone);
		
		p2.add(homeAddress);
		p2.add(jtf_homeAddress);
		
		p2.add(professionalPhone);
		p2.add(jtf_professionalPhone);
		
		p2.add(professionalAddress);
		p2.add(jtf_professionalAddress);
		
		p2.add(email);
		p2.add(jtf_email);
		
		p2.add(website);
		p2.add(jtf_website);
		
		p2.add(group);
		p2.add(jtf_group);
		

		
		
		p2.setLayout(new GridLayout(20, 2, 5, 5));
		JPanel pan = new JPanel();
		pan.add(b_return);
		pan.add(b_save);
		
		
		JLabel labelA = new JLabel(" ");
		JLabel labelB = new JLabel("             ");
	
		this.add(p2, BorderLayout.CENTER);
		this.add(l,BorderLayout.NORTH);
		this.add(pan, BorderLayout.SOUTH);
		this.add(labelA, BorderLayout.WEST);
		this.add(labelB, BorderLayout.EAST);
		
		w.setWindowProfile(this);
		
		s = new SaveModificationsController(w, this, c);
		r = new ReturnController(w);
		b_save.addActionListener(this.s);
		b_return.addActionListener(this.r);
		
	}
	
	
	public JTextField getJtf_website() {
		return jtf_website;
	}


	public void setJtf_website(JTextField jtf_website) {
		this.jtf_website = jtf_website;
	}


	public JTextField getJtf_group() {
		return jtf_group;
	}


	public void setJtf_group(JTextField jtf_group) {
		this.jtf_group = jtf_group;
	}



	public JTextField getJtf_professionalPhone() {
		return jtf_professionalPhone;
	}


	public void setJtf_professionalPhone(JTextField jtf_professionalPhone) {
		this.jtf_professionalPhone = jtf_professionalPhone;
	}


	public JTextField getJtf_homeAddress() {
		return jtf_homeAddress;
	}


	public void setJtf_homeAddress(JTextField jtf_homeAddress) {
		this.jtf_homeAddress = jtf_homeAddress;
	}


	public JTextField getJtf_professionalAddress() {
		return jtf_professionalAddress;
	}


	public void setJtf_professionalAddress(JTextField jtf_professionalAddress) {
		this.jtf_professionalAddress = jtf_professionalAddress;
	}


	public JTextField getJtf_email() {
		return jtf_email;
	}


	public void setJtf_email(JTextField jtf_email) {
		this.jtf_email = jtf_email;
	}


	public JTextField getJtf_name() {
		return jtf_name;
	}


	public void setJtf_name(JTextField jtf_name) {
		this.jtf_name = jtf_name;
	}


	public JTextField getJtf_fname() {
		return jtf_fname;
	}


	public void setJtf_fname(JTextField jtf_fname) {
		this.jtf_fname = jtf_fname;
	}


	public JTextField getJtf_phone() {
		return jtf_phone;
	}


	public void setJtf_phone(JTextField jtf_phone) {
		this.jtf_phone = jtf_phone;
	}



}
